<?php
namespace app\controllers;

use app\base\BaseAppController;
use common\services\BannerServices;
use common\services\LogServices;
use common\services\NewsServices;
use common\services\VideoServices;
use Yii;
use yii\filters\VerbFilter;

/**
 * Site controller
 */
class SiteController extends BaseAppController
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    //'logout' => ['post'],
                ],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionIndex()
    {
        //banner
        $bannerServices = new BannerServices();
        $guide = $bannerServices->getPageBanner('guide');
        if (!empty($guide)) {
            //日志
            LogServices::insertAccessLog('guide');
            return $this->render('guide', [
                'guide' => $guide,
            ]);
        }
        $banner = $bannerServices->getPageBanner('index');
        //新闻
        $newsServices = new NewsServices();
        $params = [
            'ajax' => 1
        ];
        $news = $newsServices->search($params);
        //视频
        $videoServices = new VideoServices();
        $params = [
            'is_index' => 1,
            'ajax' => 1,
            'limit' => 12,
            'section' => $this->clientSection,
        ];
        $video = $videoServices->search($params);
        //日志
        LogServices::insertAccessLog('index');
        return $this->render('index', [
            'banner' => $banner,
            'news' => $news['data'],
            'video' => $video['data'],
        ]);
    }

    public function actionError(){
        return $this->render('error');
    }

}
